﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
namespace MyWeb.Data
{
	public class ShopDAL : SqlDataProvider
	{

		#region[Shop_GetbyAll]
		public DataTable Shop_GetByAll()
		{
			using (var cmd = new SqlCommand("sp_Shop_GetByAll", GetConnection()))
			{
				cmd.CommandType = CommandType.StoredProcedure;
				var da = new SqlDataAdapter(cmd);
				var dt = new DataTable();
				da.Fill(dt);
				return dt;
			}
		}
		#endregion
		#region[Shop_GetbyId]
		public DataTable Shop_GetById(string ID)
		{
			using (var cmd = new SqlCommand("sp_Shop_GetById", GetConnection()))
			{
				cmd.CommandType = CommandType.StoredProcedure;
				cmd.Parameters.Add(new SqlParameter("@Id", ID));
				var da = new SqlDataAdapter(cmd);
				var dt = new DataTable();
				da.Fill(dt);
				return dt;
			}
		}
		#endregion
		#region[Shop_GetbyTop]
		public DataTable Shop_GetByTop(string Top, string Where, string Order)
		{
			using (var cmd = new SqlCommand("sp_Shop_GetByTop", GetConnection()))
			{
				cmd.CommandType = CommandType.StoredProcedure;
				var da = new SqlDataAdapter(cmd);
				cmd.Parameters.Add(new SqlParameter("@Top",Top));
				cmd.Parameters.Add(new SqlParameter("@Where",Where));
				cmd.Parameters.Add(new SqlParameter("@Order",Order));
				var dt = new DataTable();
				da.Fill(dt);
				return dt;
			}
		}
		#endregion
		#region[Shop_GetbyProvince_Id]
		public DataTable Shop_GetByProvince_Id(string Province_Id)
		{
			using (var cmd = new SqlCommand("sp_Shop_GetByProvince_Id", GetConnection()))
			{
				cmd.CommandType = CommandType.StoredProcedure;
				cmd.Parameters.Add(new SqlParameter("@Province_Id", Province_Id));
				var da = new SqlDataAdapter(cmd);
				var dt = new DataTable();
				da.Fill(dt);
				return dt;
			}
		}
		#endregion
		#region[Shop_Insert]
		public void Shop_Insert(ShopInfo Data)
		{
			using (var cmd = new SqlCommand("sp_Shop_Insert", GetConnection()))
			{
				cmd.CommandType = CommandType.StoredProcedure;
				cmd.Parameters.Add(new SqlParameter("@Name", Data.ShopName));
				cmd.Parameters.Add(new SqlParameter("@Address", Data.Address));
				cmd.Parameters.Add(new SqlParameter("@Tel", Data.Tel));
				cmd.Parameters.Add(new SqlParameter("@Province_Id", Data.Province_Id));
				cmd.ExecuteNonQuery();
			}
		}
		#endregion
		#region[Shop_Update]
		public void Shop_Update(ShopInfo Data)
		{
			using (var cmd = new SqlCommand("sp_Shop_Update", GetConnection()))
			{
				cmd.CommandType = CommandType.StoredProcedure;
				cmd.Parameters.Add(new SqlParameter("@Id", Data.Idshop));
				cmd.Parameters.Add(new SqlParameter("@Name", Data.ShopName));
				cmd.Parameters.Add(new SqlParameter("@Address", Data.Address));
				cmd.Parameters.Add(new SqlParameter("@Tel", Data.Tel));
				cmd.Parameters.Add(new SqlParameter("@Province_Id", Data.Province_Id));
				cmd.ExecuteNonQuery();
			}
		}
		#endregion
		#region[Shop_Delete]
		public void Shop_Delete(string Data)
		{
			using (var cmd = new SqlCommand("sp_Shop_Delete", GetConnection()))
			{
				cmd.CommandType = CommandType.StoredProcedure;
				cmd.Parameters.Add(new SqlParameter("@Id", Data));
				cmd.ExecuteNonQuery();
			}
		}
		#endregion
	}
}